/**
 * FileName: SdUtil.java
 * @Description: TODO(用一句话描述该文件做什么)
 * All rights Reserved, Designed By 21winmess
 * Copyright: Copyright(C) 2010-2011 
 * Company 21winmess DaLian LTD.
 * @author: Matrix xu
 * @version V2.0
 * Createdate: 2012-12-14 上午10:35:45
 *
 * Modification History:
 * Date Author Version Discription
 * -----------------------------------------------------------------------------------
 * 2012-12-14 Qute_Android2.0
 * Why & What is modified: <修改原因描述>
 */
package com.me.safebox.utils;

import java.io.File;
import java.util.Date;

import android.os.Environment;

import com.me.safebox.utils.Dev_MountInfo.DevInfo;

/**
 * @ClassName: SdUtil
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: Matrix
 * @date: 2012-12-14 上午10:35:45
 * 
 */
public class SdUtil {

	public SdUtil() {
	}

	/**
	 * 检查外置SD卡是否存在
	 * 
	 * @param externalSdPath
	 * @return
	 */
	private static boolean detectExternalSdCardAvailability(String externalSdPath) {

		boolean result = false;
		try {
			Date now = new Date();
			long times = now.getTime();
			String fileName = externalSdPath + "/" + times + ".test";
			File file = new File(fileName);
			result = file.createNewFile();
			file.delete();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 检查SD卡
	 * 
	 * @return
	 */
	public static MountInfo checkMountInfo() {
		MountInfo mountInfo = new MountInfo();
		Dev_MountInfo dev = Dev_MountInfo.getInstance();
		DevInfo external_info = dev.getExternalInfo();
		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
			mountInfo.isInternalsdAvaliable = true;
		}

		if (external_info != null && detectExternalSdCardAvailability(external_info.getPath())) {
			mountInfo.isExternalSdAvaliable = true;
			mountInfo.externalSdPath = external_info.getPath();
		} else {
			mountInfo.isExternalSdAvaliable = false;
		}
		return mountInfo;
	}
}
